var socket;
//connect();
function connect() {
    socket = io(SockctIo_Path, {secure: true,'force new connection':true,query: 'loginUserNum=' + userName,transports:['websocket','xhr-polling','jsonp-polling']});
    socket.on('connect', function () {
        console.log("消息通知 连接成功");
        socket.emit('text','{"username":"'+userName+'","info":"'+nickname+'连接成功" ,"type":"2" }');
        noticeSend("连接成功",nickname+"账户成功连接客户的消息通知,请注意右下角的消息通知");
    }).on('push_person', function (data) {
        noticeSend(data.title,data.text);
        socket.emit('text','{"username":"'+userName+'" , "info":"'+nickname+'接收到个人信息", "uuid":"'+data.uuid+'" ,"type":"6" }');
    }).on('push_month_report',function (data) {
        noticeSend(data.title,data.text);
        socket.emit('text','{"username":"'+userName+'" , "info":"'+nickname+'接收到月报", "uuid":"'+data.uuid+'" ,"type":"5" }');
    }).on('push_dept_recevice',function (data) {
        noticeSend(data.title,data.text);
        socket.emit('text','{"username":"'+userName+'" , "info":"'+nickname+'接收到部门推送信息", "uuid":"'+data.uuid+'" ,"type":"4" }');
    }).on('push_other_recevice',function (data) {
        noticeSend(data.title,data.text);
        socket.emit('text','{"username":"'+userName+'" , "info":"'+nickname+'接收到其他推送信息", "uuid":"'+data.uuid+'" ,"type":"3" }');
    }).on('disconnect', function () {
        console.log("下线成功");
    });
}
function noticeSend(title,content){
    window.Notification.permission = "granted";
    if(window.Notification) {
        if(window.Notification.permission == "granted") {
            // Push.create(title, {
            //     body: content, requireInteraction: true,
            //     onClick: function () {window.focus();this.close();},
            //     vibrate: [200, 100, 200, 100, 200, 100, 200]
            // });
           new Notification(title, {
                body: content
            });
        } else {window.Notification.requestPermission(); alert('你的浏览器禁用了消息提示功能');}
    } else{
        alert('你的浏览器不支持此消息提示功能,请使用chrome内核的浏览器!');
        $JuXue.n_danger("请设置浏览器允许消息通知");
    }
}
